/*
 * $Id: Tcp4Address.cc,v 1.8 2005-07-23 14:05:45 bacon Exp $
 */

#include <xpp/net/Tcp4Address.h>
#include <xpp/net/Socket.h>
#include <xp/bas/assert.h>

namespace xpp
{
	namespace net
	{

		Tcp4Address::Tcp4Address (): TcpAddress (V4)
		{
		}

		Tcp4Address::Tcp4Address (const InetAddress& adr): TcpAddress (adr)
		{
			xp_assert (this->family() == adr.family());
		}

		Tcp4Address::Tcp4Address (
			const struct sockaddr_in& adr): TcpAddress (adr)
		{
		}

		Tcp4Address::Tcp4Address (xp_uint16_t port, xp_uint32_t ip): TcpAddress (V4)
		{
			struct sockaddr_in sin;
			xp_memset (&sin, 0, xp_sizeof(sin));
			sin.sin_family = V4;
			sin.sin_addr.s_addr = ip;
			sin.sin_port = port;
			TcpAddress::operator= (sin);
		}

		Tcp4Address& Tcp4Address::operator= (const Tcp4Address& adr) 
		{
			TcpAddress::operator= (adr);
			return *this;
		}

		Tcp4Address& Tcp4Address::operator= (const InetAddress& adr) 
		{
			xp_assert (this->family() == adr.family());
			TcpAddress::operator= (adr);
			return *this;
		}

		xp_uint16_t Tcp4Address::port () const
		{
			struct sockaddr_in* p;
			p = (struct sockaddr_in*)this->storage();
			return p->sin_port;
		}

		xp_uint32_t Tcp4Address::ip () const
		{
			struct sockaddr_in* p;
			p = (struct sockaddr_in*)this->storage();
			return p->sin_addr.s_addr;
		}
	}
}
